// 成品销售出库查询 -- wzhg
import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal } from 'antd';
import AddPage from './addPage'
import UpdatePage from './UpdatePage'
import CheckPage from './CheckPage'
import ListDetail from './ListDetailPage.js'

import {fetchData} from '../../../components/AjaxConsumer'


export default class ListProSellOutPage extends Component{
    constructor(props) {
        super(props);
        //行操作列表-已弃用
        this.rowOperation = [
            
        ];
        //header 操作列表111
        this.headerOperation = [
            {
                handleName: 'add',
                showName: '创建',
                iconClass: 'plus',
                permission: 'sellout-create'
            },
            {
                handleName: 'edit',
                showName: '修改',
                iconClass: 'edit',
                permission: 'sellout-edit'
            },{
                handleName: 'delete',
                showName: '删除',
                iconClass: 'delete',
                permission: 'sellout-del'
            }, {
                handleName: 'check',
                showName: '审核',
                iconClass: 'eye',
                permission: 'sellout-audit'
                // permission: 'sellout-edit'
            },{
                handleName: 'info',
                showName: '详情',
                iconClass: 'info'
            }
            // {
            //     handleName: 'exp',
            //     showName: '导出',
            //     iconClass: 'exp'
            // }

        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'sellOutId',
            data: [
                {
                    showName: 'sellOutId',
                    columnName: 'sellOutId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '销售出库单号',
                    columnName: 'sellOutNo',
                    columnWidth: 130
                },
                // {
                //     showName: '采购订单号',
                //     columnName: 'purchaseNo'
                // },
                {
                    showName: '合同编号',
                    columnName: 'contractNo',
                    columnWidth: 120
                },
                {
                    showName: '型号',
                    columnName: 'model',
                    columnWidth: 120
                },
                {
                    showName: '型号类型',
                    columnName: 'modelType',
                    columnWidth: 120
                },
                {
                    showName: '单位',
                    columnName: 'unit',
                    columnWidth: 80
                },
                {
                    showName: '需求数量',
                    columnName: 'requireAmount',
                    columnWidth: 80
                },
                {
                    showName: '实发数量',
                    columnName: 'realAmount',
                    columnWidth: 80
                },
                {
                    showName: '计划日期',
                    columnName: 'outPlanTime',
                    columnWidth: 135
                },
                {
                    showName: '状态',
                    columnName: 'sellOutStatus',
                    columnWidth: 100,
                    showOption: [
                        {
                            optionKey: '0',
                            optionShow: '新建'
                        },{
                            optionKey: '1',
                            optionShow: '出库中'
                        },{
                            optionKey: '2',
                            optionShow: '出库完成'
                        },{
                            optionKey: '3',
                            optionShow: '审核通过'
                        },{
                            optionKey: '4',
                            optionShow: '审核不通过'
                        }
                    ]
                },
                {
                    showName: '创建日期',
                    columnName: 'gmtCreate',
                    columnWidth: 135
                },
                {
                    showName: '备注',
                    columnName: 'remark',
                    columnWidth: 120
                }
            ]
        };

        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        this.searchComponentData = [
            {
                showName: '型号类型',
                name: 'modelType',
                type: 'select',
                optionList: [//下拉框的信息
                ]
            },
            {
                showName:'计划日期',
                name:'outPlanTime',
                type: 'date',
                maxName:'outPlanTimeMax',
                minName:'outPlanTimeMin'
            },
            {
                showName:'创建日期',
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin'
            },{
                showName: '需求数量',
                name:'requireAmount',
                type: 'number',
                maxName:'requireAmountMax', //最大值
                minName:'requireAmountMin'  //最小值
            },{
                showName:'实发数量',
                name:'realAmount',
                type:'number',
                maxName:'realAmountMax',
                minName:'realAmountMin'
            },
            {
                showName:'状态',
                name:'sellOutStatus',
                type: 'select',
                optionList:[
                    {
                        optionkey:'',
                        optionShow:''
                    },
                    {
                        optionkey:'0',
                        optionShow:'新建'
                    },{
                        optionkey:'4',
                        optionShow:'审核不通过'
                    },{
                        optionkey:'3',
                        optionShow:'审核通过'
                    },{
                        optionkey:'1',
                        optionShow:'出库中'
                    },{
                        optionkey:'2',
                        optionShow:'出库完成'
                    }
                ]
            }
        ];

    }

    // 行操作
    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'exp'){
            // this.expHandle(rowObj);
        }else if(strHandles === 'add'){
            this.addHandle(rowObj);
        }else if(strHandles == 'edit'){
            this.editHandle(rowObj);
        }else if(strHandles == 'check'){
            this.checkHandle(rowObj);
        }else if (strHandles === 'delete') {
            this.deleteHandle(rowObj);
        }if(strHandles == 'doubleClick'){
            this.infoHandle(rowObj);
        }if(strHandles == 'info'){
            this.infoHandle(rowObj);
        }
    }

    infoHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.listDetail.editHandle(rowObj[0].data);
        }
    };

    editHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updatePage.editHandle(rowObj);
        }
    };

    deleteHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updatePage.deleteHandle(rowObj)
        }
    }

    checkHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.checkPage.checkHandle(rowObj);
        }
    };

    //按照库位新增
    addHandle = () => {
        this.refs.addPage.addHandle();
    };

    componentWillMount() {
        const dicType = 'model_type_p';
        const options= {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition:{}
        };
        //先写死，后面再改
        fetchData(this, options, this.dicInitCallBackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData)=>{
        //alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });

        //alert('optionList' + JSON.stringify(optionList, null, 4));
        this.tableColumn.data[4].showOption = optionList;
        this.searchComponentData[0].optionList = optionList;
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.proSellOutList.refreshHandle();
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    ref = 'proSellOutList'
                    title="销售出库查询"
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/product/prosellout/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />
                <AddPage
                    ref="addPage"
                    refreshHandle = {this.refreshHandle}
                />
                <UpdatePage
                    ref="updatePage"
                    refreshHandle = {this.refreshHandle}
                />
                 <CheckPage
                    ref="checkPage"
                    refreshHandle = {this.refreshHandle}
                />

                <ListDetail
                    ref="listDetail"
                    refreshHandle = {this.refreshHandle}
                />
            </div>
        )
        
    }

}